<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Appendix H. Csound Double (64-bit) vs. Float (32-bit)</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="prev" href="MiscSf2.html" title="Appendix G. SoundFont2 File Format" />
    <link rel="next" href="MiscGlossary.html" title="Glossary" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">Appendix H. Csound Double (64-bit) vs. Float (32-bit)</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="MiscSf2.html">Prev</a> </td>
          <th width="60%" align="center"> </th>
          <td width="20%" align="right"> <a accesskey="n" href="MiscGlossary.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="appendix">
      <div class="titlepage">
        <div>
          <div>
            <h1 class="title"><a id="MiscCsound64"></a>Appendix H. Csound Double (64-bit) vs. Float (32-bit)</h1>
          </div>
        </div>
      </div>
      <p>
    Csound can be built to use 64-bit DOUBLES internally to do processing versus regular Csound's 32-bit FLOATS. This larger resolution for processing internally yields a much "cleaner" sound but at the expense of extended processing time. Because it does require much longer to process, Csound compiled for doubles is typicaly used after a work is finished for a final production run. If you are using csound for realtime output, you should use the 32-bit (float) version, which provides faster output. For offline rendering, you can use either, but for the final master, the 64-bit version will produce higher quality output.
  </p>
      <p>
    The actual resolution should be the same as for the type of the audio sample variable. For "float" Csound, that is a 32-bit, single-precision floating point number. It has 24 bits of precision in the mantissa. For "double" Csound, that is a 64-bit, double-precision floating point number in the mantissa. It has 52 bits of precision. For each decimal digit, there is between 3 and 4 bits. So, there are 7 digits of precision for "float" and 16 digits of precision for "double."
  </p>
      <p>
    For each multiplication or division, depending on whether the operands are integers, rational numbers, repeating decimals, or irrational decimals, there may or may not be rounding error in the result. If there is rounding error, it is at most 1 bit of lost precision per operation (in addition to any rounding in the binary representation of rational or real numbers).
  </p>
      <p>
    For float samples, if the signal stays within the mantissa, the signal to noise ratio is 6.02 times 24, or 144 dB. At worst, each operation will create 6.02 dB of additional noise due to rounding error. Our ears have an effective dynamic range of 120 to 130 dB, but we like our music compressed to a dynamic range of AT MOST 60 dB (and usually much less, say 20 dB). That gives us (144 - 60) / 6.02 = about 10 worst-case operations before we could possibly hear any degradation. In practice, we have several times that many operations before we hear any degradation or noise.
  </p>
      <p>
    For double samples, if the signal stays within the mantissa, the signal to noise ratio is 6.02 times 52, or 313 dB. At worst, each operation will create 6.02 dB of additional noise due to rounding error.  That gives us (313 - 60) / 6.02 = about 42, in practice several times that, of operations before there is any audible degradation or noise.
  </p>
      <p>
    But if you trace the number of arithmetic operations in typical Csound instruments or other software synthesizers, the very complex instruments definitely are pushing into the range of audible degradation on good monitors with float, so it is no surprise that in some cases blindfold, controlled ABX testing confirms <span class="emphasis"><em>occasional</em></span> audible differences between music synthesized with "float" Csound versus the same music synthesized with "double" Csound. Equally, it is no surprise that there are easily audible differences between digital and analog implementations of the same synthesis algorithms.
  </p>
      <p>
    There is a good deal more "digital signal processing headroom" with double Csound, and therefore it should be used for all music rendered for critical listening. The float version should only be used where its speed advantage of about 15% is critical for real-time performance.
  </p>
      <h2><a id="idp235519248"></a>Notes On Using Csound built for double precision</h2>
      <p>
    </p>
      <div class="orderedlist">
        <ol class="orderedlist" type="1">
          <li class="listitem">
            <p>hetro, PVOC-EX analysis and pvanal files generated for 32-bit Csound (float) will work with 64-bit Csound (double precision).</p>
          </li>
          <li class="listitem">
            <p>All other analysis formats can be generated in a
      way for cross-use between 32 and 64 bit versions and big-endian
      and little-endian architectures, if the <span class="emphasis"><em>-X</em></span>
      option is used in generation.  The older format in csound5 is
      still generatable but is not machins independant.</p>
          </li>
        </ol>
      </div>
      <p>
  </p>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="MiscSf2.html">Prev</a> </td>
          <td width="20%" align="center"> </td>
          <td width="40%" align="right"> <a accesskey="n" href="MiscGlossary.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">Appendix G. SoundFont2 File Format </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> Glossary</td>
        </tr>
      </table>
    </div>
  </body>
</html>
